package com.medical.doctor.controller;

import java.util.List;

import com.medical.common.core.utils.poi.ExcelUtil;
import com.medical.doctor.vo.DiagnosticRecordVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.medical.common.log.annotation.Log;
import com.medical.common.log.enums.BusinessType;
import com.medical.common.security.annotation.RequiresPermissions;
import com.medical.doctor.domain.DiagnosticRecord;
import com.medical.doctor.service.IDiagnosticRecordService;
import com.medical.common.core.web.controller.BaseController;
import com.medical.common.core.domain.Result;
import com.medical.common.core.web.page.TableDataInfo;

import javax.servlet.http.HttpServletResponse;

/**
 * 诊断管理Controller
 *
 * @author medical
 * @date 2024-07-22
 */
@RestController
@RequestMapping("/diagnosis")
public class DiagnosticRecordController extends BaseController
{
    @Autowired
    private IDiagnosticRecordService diagnosticRecordService;

    /**
     * 查询诊断管理列表
     */
    @RequiresPermissions("doctor:diagnosis:list")
    @GetMapping("/list")
    public Result<TableDataInfo> list(DiagnosticRecord diagnosticRecord)
    {
        startPage();
        List<DiagnosticRecordVo> list = diagnosticRecordService.selectDiagnosticRecordList(diagnosticRecord);
        return getDataTable(list);
    }


    /**
     * 导出诊断管理列表
     */
    @RequiresPermissions("doctor:diagnosis:export")
    @Log(title = "诊断管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DiagnosticRecord diagnosticRecord)
    {
        List<DiagnosticRecordVo> list = diagnosticRecordService.selectDiagnosticRecordList(diagnosticRecord);
        ExcelUtil<DiagnosticRecordVo> util = new ExcelUtil<DiagnosticRecordVo>(DiagnosticRecordVo.class);
        util.exportExcel(response, list, "诊断管理数据");
    }

    /**
     * 获取诊断管理详细信息
     */
    @RequiresPermissions("doctor:diagnosis:query")
    @GetMapping(value = "/{diagnoseId}")
    public Result getInfo(@PathVariable("diagnoseId") Long diagnoseId)
    {
        return success(diagnosticRecordService.selectDiagnosticRecordByDiagnoseId(diagnoseId));
    }

    /**
     * 新增诊断管理
     */
    @RequiresPermissions("doctor:diagnosis:add")
    @Log(title = "诊断管理", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody DiagnosticRecord diagnosticRecord)
    {
        return toAjax(diagnosticRecordService.insertDiagnosticRecord(diagnosticRecord));
    }

    /**
     * 修改诊断管理
     */
    @RequiresPermissions("doctor:diagnosis:edit")
    @Log(title = "诊断管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody DiagnosticRecord diagnosticRecord)
    {
        return toAjax(diagnosticRecordService.updateDiagnosticRecord(diagnosticRecord));
    }

    /**
     * 删除诊断管理
     */
    @RequiresPermissions("doctor:diagnosis:remove")
    @Log(title = "诊断管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{diagnoseIds}")
    public Result remove(@PathVariable Long[] diagnoseIds)
    {
        return toAjax(diagnosticRecordService.deleteDiagnosticRecordByDiagnoseIds(diagnoseIds));
    }
}
